from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-02 14:07:30.677501
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 02, May, 2021
Time: 14:07:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9286
Nobs: 279.000 HQIC: -48.6300
Log likelihood: 3376.49 FPE: 4.74558e-22
AIC: -49.0999 Det(Omega_mle): 3.45658e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.425053 0.119795 3.548 0.000
L1.Burgenland 0.071435 0.059697 1.197 0.231
L1.Kärnten -0.225643 0.052962 -4.260 0.000
L1.Niederösterreich 0.088810 0.128461 0.691 0.489
L1.Oberösterreich 0.224110 0.123866 1.809 0.070
L1.Salzburg 0.272042 0.068339 3.981 0.000
L1.Steiermark 0.109962 0.086897 1.265 0.206
L1.Tirol 0.122394 0.060289 2.030 0.042
L1.Vorarlberg -0.035625 0.055281 -0.644 0.519
L1.Wien -0.043156 0.111499 -0.387 0.699
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.441903 0.138500 3.191 0.001
L1.Burgenland 0.004989 0.069018 0.072 0.942
L1.Kärnten 0.329372 0.061232 5.379 0.000
L1.Niederösterreich 0.108389 0.148519 0.730 0.466
L1.Oberösterreich -0.066220 0.143207 -0.462 0.644
L1.Salzburg 0.221730 0.079010 2.806 0.005
L1.Steiermark 0.091849 0.100465 0.914 0.361
L1.Tirol 0.136799 0.069702 1.963 0.050
L1.Vorarlberg 0.151551 0.063913 2.371 0.018
L1.Wien -0.410715 0.128909 -3.186 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.268909 0.060754 4.426 0.000
L1.Burgenland 0.103689 0.030275 3.425 0.001
L1.Kärnten -0.013187 0.026860 -0.491 0.623
L1.Niederösterreich 0.085408 0.065149 1.311 0.190
L1.Oberösterreich 0.286139 0.062819 4.555 0.000
L1.Salzburg 0.016375 0.034658 0.472 0.637
L1.Steiermark -0.000769 0.044070 -0.017 0.986
L1.Tirol 0.069623 0.030575 2.277 0.023
L1.Vorarlberg 0.074306 0.028036 2.650 0.008
L1.Wien 0.111892 0.056547 1.979 0.048
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210625 0.058193 3.619 0.000
L1.Burgenland 0.028676 0.028999 0.989 0.323
L1.Kärnten 0.009269 0.025727 0.360 0.719
L1.Niederösterreich 0.055145 0.062402 0.884 0.377
L1.Oberösterreich 0.395042 0.060170 6.565 0.000
L1.Salzburg 0.080445 0.033197 2.423 0.015
L1.Steiermark 0.132553 0.042212 3.140 0.002
L1.Tirol 0.050508 0.029286 1.725 0.085
L1.Vorarlberg 0.081037 0.026854 3.018 0.003
L1.Wien -0.043943 0.054163 -0.811 0.417
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477676 0.113701 4.201 0.000
L1.Burgenland 0.100361 0.056660 1.771 0.077
L1.Kärnten 0.009176 0.050268 0.183 0.855
L1.Niederösterreich 0.008777 0.121926 0.072 0.943
L1.Oberösterreich 0.122641 0.117565 1.043 0.297
L1.Salzburg 0.052955 0.064862 0.816 0.414
L1.Steiermark 0.068412 0.082476 0.829 0.407
L1.Tirol 0.204917 0.057222 3.581 0.000
L1.Vorarlberg 0.033672 0.052469 0.642 0.521
L1.Wien -0.071920 0.105827 -0.680 0.497
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213100 0.089879 2.371 0.018
L1.Burgenland -0.011410 0.044789 -0.255 0.799
L1.Kärnten -0.006341 0.039736 -0.160 0.873
L1.Niederösterreich -0.015223 0.096380 -0.158 0.875
L1.Oberösterreich 0.416207 0.092933 4.479 0.000
L1.Salzburg 0.013041 0.051273 0.254 0.799
L1.Steiermark -0.027163 0.065196 -0.417 0.677
L1.Tirol 0.162216 0.045233 3.586 0.000
L1.Vorarlberg 0.056790 0.041476 1.369 0.171
L1.Wien 0.204575 0.083655 2.445 0.014
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219542 0.108972 2.015 0.044
L1.Burgenland 0.020782 0.054304 0.383 0.702
L1.Kärnten -0.071438 0.048177 -1.483 0.138
L1.Niederösterreich -0.061534 0.116855 -0.527 0.598
L1.Oberösterreich 0.019296 0.112676 0.171 0.864
L1.Salzburg 0.082763 0.062165 1.331 0.183
L1.Steiermark 0.324033 0.079046 4.099 0.000
L1.Tirol 0.460982 0.054842 8.406 0.000
L1.Vorarlberg 0.145725 0.050287 2.898 0.004
L1.Wien -0.137091 0.101426 -1.352 0.176
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207782 0.130363 1.594 0.111
L1.Burgenland 0.043354 0.064963 0.667 0.505
L1.Kärnten -0.073961 0.057634 -1.283 0.199
L1.Niederösterreich 0.112105 0.139793 0.802 0.423
L1.Oberösterreich 0.015837 0.134793 0.117 0.906
L1.Salzburg 0.191300 0.074367 2.572 0.010
L1.Steiermark 0.131252 0.094562 1.388 0.165
L1.Tirol 0.055674 0.065607 0.849 0.396
L1.Vorarlberg 0.105868 0.060157 1.760 0.078
L1.Wien 0.218820 0.121335 1.803 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.538480 0.072035 7.475 0.000
L1.Burgenland -0.015662 0.035897 -0.436 0.663
L1.Kärnten -0.017277 0.031847 -0.542 0.587
L1.Niederösterreich 0.092484 0.077245 1.197 0.231
L1.Oberösterreich 0.306414 0.074483 4.114 0.000
L1.Salzburg 0.015470 0.041093 0.376 0.707
L1.Steiermark -0.043433 0.052252 -0.831 0.406
L1.Tirol 0.081307 0.036252 2.243 0.025
L1.Vorarlberg 0.102354 0.033241 3.079 0.002
L1.Wien -0.055889 0.067046 -0.834 0.405
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.159555 0.087429 0.165563 0.215493 0.076925 0.085602 -0.000769 0.161896
Kärnten 0.159555 1.000000 0.053398 0.212146 0.185645 -0.066028 0.176195 0.020322 0.303663
Niederösterreich 0.087429 0.053398 1.000000 0.246278 0.087416 0.320792 0.145170 0.023880 0.307688
Oberösterreich 0.165563 0.212146 0.246278 1.000000 0.302989 0.259509 0.101820 0.061294 0.138756
Salzburg 0.215493 0.185645 0.087416 0.302989 1.000000 0.149456 0.063209 0.090011 0.016298
Steiermark 0.076925 -0.066028 0.320792 0.259509 0.149456 1.000000 0.095687 0.101042 -0.102170
Tirol 0.085602 0.176195 0.145170 0.101820 0.063209 0.095687 1.000000 0.151613 0.155107
Vorarlberg -0.000769 0.020322 0.023880 0.061294 0.090011 0.101042 0.151613 1.000000 -0.011774
Wien 0.161896 0.303663 0.307688 0.138756 0.016298 -0.102170 0.155107 -0.011774 1.000000